<?php
namespace App\Http\Controllers\Admin;

use App\Service\Admin\IndexService;
use Illuminate\Http\Request;

class IndexController extends BaseController
{
    //首页

    //登录
    public function dologin(Request $request)
    {
        $uname = $request->post('uname', '');
        $passwd = $request->post('passwd', '');
        if (!$uname) {
            return $this->toJson(-2, '账号必须的');
        }
        if (!$passwd) {
            return $this->toJson(-2, '密码必须的');
        }
        if (strlen($passwd) < 2 || strlen($passwd) > 20) {
            return $this->toJson(-2, '密码必须是2-20位');
        }
        $res = IndexService::dologin($uname, $passwd);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }
}